package com.jjw.springbootcvs.service.impl;


import com.jjw.springbootcvs.constant.MessageConstant;
import com.jjw.springbootcvs.mapper.SysRoleMapper;
import com.jjw.springbootcvs.pojo.entity.SysRole;
import com.jjw.springbootcvs.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiaojuan
 * @Date 2024/11/4
 * @Description
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Override
    public List<SysRole> getAllRoleList() {
        return sysRoleMapper.getAllRoleList();
    }

    @Override
    public void add(SysRole sysRole) {
        sysRoleMapper.insertSelective(sysRole);
    }

    @Override
    public SysRole getRoleByCode(String roleCode) {
        SysRole sysRole = sysRoleMapper.getRoleByCode(roleCode);
        if (sysRole != null){
            throw new RuntimeException(MessageConstant.ROLE_CODE_EXIST);
        }
        return sysRole;
    }

    @Override
    public void delete(Long id) {
        sysRoleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public SysRole getRoleById(Long id) {
        return sysRoleMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(SysRole sysRole) {
        sysRoleMapper.updateByPrimaryKeySelective(sysRole);
    }
}
